﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Acms.AcmsControls.ContentControls.FrontEnd
{
    public class MetaDescription : BasePostPropertyControl
    {
        public override void DataBind()
        {
            var post = FindCurrentPost();
            if(post != null && !string.IsNullOrEmpty(post.Summary))
            {
                this.Content = post.Summary;
            }
            base.DataBind();
        }

        public string Content { get; set; }

        protected override object SaveViewState()
        {
            ViewState["Content"] = Content;
            return base.SaveViewState();
        }

        protected override void LoadViewState(object savedState)
        {
            base.LoadViewState(savedState);
            Content = ViewState["Content"] as string;
        }
        protected override void Render(System.Web.UI.HtmlTextWriter writer)
        {
            if (!string.IsNullOrEmpty(Content))
            {
                writer.Write(string.Format("<meta name=\"Description\" content=\"{0}\"/>", Content));
            }
        }
    }
}
